package com.keyancompany.zhongbaopingtai.fragment;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.keyancompany.zhongbaopingtai.R;
import com.keyancompany.zhongbaopingtai.activity.DocumentShareActivity;
import com.keyancompany.zhongbaopingtai.model.SharePager;
import com.keyancompany.zhongbaopingtai.weight.EmptyView;

/**
 * 讨论区
 * 已废弃
 */
public class SharedFragment extends Fragment {

    // TODO: Customize parameter argument names
    private static final String ARG_COLUMN_COUNT = "column-count";
    private static final String TUPE = "type";
    // TODO: Customize parameters
    private int mColumnCount = 1;
    private int type = 1;//这个没用
    private OnshareInteractionListener mListener;

    /**
     * Mandatory empty constructor for the fragment manager to instantiate the
     * fragment (e.g. upon screen orientation changes).
     */
    public SharedFragment() {
    }

    /**
     * @param columnCount
     * @param type
     * @return
     */
    public static SharedFragment newInstance(int columnCount, int type) {
        SharedFragment fragment = new SharedFragment();
        Bundle args = new Bundle();
        args.putInt(ARG_COLUMN_COUNT, columnCount);
        args.putInt(TUPE, type);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        if (getArguments() != null) {
            mColumnCount = getArguments().getInt(ARG_COLUMN_COUNT);
            type = getArguments().getInt(TUPE);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_weekly, container, false);
        RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.list);
        EmptyView emptyView = (EmptyView) view.findViewById(R.id.empty_view);
        // Set the adapter
        if (mColumnCount <= 1) {
            recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
        } else {
            recyclerView.setLayoutManager(new GridLayoutManager(getActivity(), mColumnCount));
        }

        if (((DocumentShareActivity) getActivity()).getList() != null) {
//            recyclerView.setAdapter(new DocumentsAdapter(((DocumentShareActivity) getActivity()).getList(), mListener));
        }
//        if (type == 1) {//xihe这之后再看一眼哈
//            recyclerView.setVisibility(View.GONE);
//            emptyView.setVisibility(View.VISIBLE);
//        }
//        emptyView.setOnClickListener();

        return view;
    }


    @Override
    public void onAttach(Activity context) {
        super.onAttach(context);
        if (context instanceof OnshareInteractionListener) {
            mListener = (OnshareInteractionListener) context;
        } else {
            throw new RuntimeException(context.toString()
                    + " must implement OnListFragmentInteractionListener");
        }
    }

    @Override
    public void onDetach() {
        super.onDetach();
        mListener = null;
    }

    /**
     * This interface must be implemented by activities that contain this
     * fragment to allow an interaction in this fragment to be communicated
     * to the activity and potentially other fragments contained in that
     * activity.
     * <p/>
     * See the Android Training lesson <a href=
     * "http://developer.android.com/training/basics/fragments/communicating.html"
     * >Communicating with Other Fragments</a> for more information.
     */
    public interface OnshareInteractionListener {
        // TODO: Update argument type and name
        void onShareInteraction(SharePager item);
    }
}
